package com.stylefeng.guns.modular.recommend.controller;

import com.stylefeng.guns.core.base.controller.BaseController;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.beans.factory.annotation.Autowired;
import com.stylefeng.guns.core.log.LogObjectHolder;
import org.springframework.web.bind.annotation.RequestParam;
import com.stylefeng.guns.modular.system.model.Recommend;
import com.stylefeng.guns.modular.recommend.service.IRecommendService;

/**
 * 推荐模块控制器
 *
 * @author fengshuonan
 * @Date 2018-08-14 14:33:49
 */
@Controller
@RequestMapping("/recommend")
public class RecommendController extends BaseController {

    private String PREFIX = "/recommend/recommend/";

    @Autowired
    private IRecommendService recommendService;

    /**
     * 跳转到推荐模块首页
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "recommend.html";
    }

    /**
     * 跳转到添加推荐模块
     */
    @RequestMapping("/recommend_add")
    public String recommendAdd() {
        return PREFIX + "recommend_add.html";
    }

    /**
     * 跳转到修改推荐模块
     */
    @RequestMapping("/recommend_update/{recommendId}")
    public String recommendUpdate(@PathVariable Integer recommendId, Model model) {
        Recommend recommend = recommendService.selectById(recommendId);
        model.addAttribute("item",recommend);
        LogObjectHolder.me().set(recommend);
        return PREFIX + "recommend_edit.html";
    }

    /**
     * 获取推荐模块列表
     */
    @RequestMapping(value = "/list")
    @ResponseBody
    public Object list(String condition) {
        return recommendService.selectList(null);
    }

    /**
     * 新增推荐模块
     */
    @RequestMapping(value = "/add")
    @ResponseBody
    public Object add(Recommend recommend) {
        recommendService.insert(recommend);
        return SUCCESS_TIP;
    }

    /**
     * 删除推荐模块
     */
    @RequestMapping(value = "/delete")
    @ResponseBody
    public Object delete(@RequestParam Integer recommendId) {
        recommendService.deleteById(recommendId);
        return SUCCESS_TIP;
    }

    /**
     * 修改推荐模块
     */
    @RequestMapping(value = "/update")
    @ResponseBody
    public Object update(Recommend recommend) {
        recommendService.updateById(recommend);
        return SUCCESS_TIP;
    }

    /**
     * 推荐模块详情
     */
    @RequestMapping(value = "/detail/{recommendId}")
    @ResponseBody
    public Object detail(@PathVariable("recommendId") Integer recommendId) {
        return recommendService.selectById(recommendId);
    }
}
